<?php

namespace Common\Model;

/**
 * AdminInfoModel.class.php实例模型
 *
 * @author songanwei
 * @date 2016-1-8
 */
class AdminInfoModel extends BaseModel {

    protected $trueTableName = 'tb_admin_info';

    protected function _before_insert(&$data, $options) {
        // parent::_before_insert($data, $options);
    }

    protected function _before_update(&$data, $options) {
        //parent::_before_update($data, $options);
    }

    /**
     * 返回用户数据
     * @modify songanwei 2016-01-08
     * @modify trainyao 2016-01-20    修改为可获取多个用户信息
     * @param integer $userId 用户ID
     * @return type
     */
    public function getInfoByUser($userId) {
        $option = array();
        if (is_array($userId)) {
            $userId = implode(',', $userId);
        }
        if (strpos($userId, ',') !== false) {
            $option['adminlogin_id'] = array('in', $userId);
            $data = $this->where($option)->select();
        } else {
            $option['adminlogin_id'] = $userId;
            $data = $this->where($option)->find();
        }

        return empty($data) ? array() : $data;
    }

    /**
     *
     * 添加用户数据
     * @modify songanwei 2016-01-08
     * @param integer $userId  用户ID
     * @param string $headPath  头像
     * @return type
     */
    public function addInfo($userId, $headPath = '/Public/dist/Home/image/user.png') {
        $options = array(
            'adminlogin_id' => $userId,
            'headpath' => $headPath
        );
        return $this->add($options);
    }

    /**
     * 更新用户数据
     * @modify songanwei 2016-01-08
     * @param integer $userId  用户ID
     * @param string $headPath 头像
     * @return type
     */
    public function saveInfo($userId, $headPath = '') {
        $options = array('headpath' => $headPath);
        $result = $this->where(array('adminlogin_id' => $userId))->save($options);
        return $result === false ? false : true;
    }

}
